
var validateUtil = {	
	"Error_numeric" : null,
	"Error_blank" : null,
	"Error_inValid" : null,
	"Error_blankSpace" : null,
	"Error_limitNum" : null,
	"Error_mostNum" : null,
	"Error_alphanumeric" : null,
	"Error_alphabetic" : null,
	"Error_secPassword" : null,
	"Error_equal" : null,
	"Error_notEqual" : null,
	"Error_textArea" : null,
	"Error_small" : null,
	"Error_great" : null,
	"Error_early" : null,
	"Error_earlyToday" : null,
	"Error_inValidSeparator" : null,
	"Error_inValidNumber" : null,
	"Error_positive" : null,
	"Error_phone" : null,
	"TotalErrorMessage" : "",
	"errHead" : null,
	"errFoot" : null,
	"Error_adapt_field_type": null,
	"Error_adapt_not_instance": null,
  "Error_adapt_invalid_property": null,
  "Error_adapt_required" : null,
  "Error_adapt_pattern" : null,
  "Error_adapt_maxlength" : null,
  "Error_adapt_minlength" : null,
  "Error_adapt_minimum" : null,
  "Error_adapt_maximum" : null,
  "Error_adapt_enumeration" : null,
  "Error_adapt_digits" : null,
  "Error_adapt_object_required":null,
  "Error_adapt_additional" : null,
  "Error_adapt_presence" : null,
	
	"alertErrorMessage" : function(){
		if(this.TotalErrorMessage.length > 0)
			{
				var Temp = this.TotalErrorMessage;
				this.TotalErrorMessage = "";
				alert(this.errHead + Temp + this.errFoot);				
			}
	},
	"getDesc" : function(fieldDesc){
    return fieldDesc;
	},
	
	"setErrorMessage" : function(Message){
		this.TotalErrorMessage+=Message + "\n";
		return(false);
	}	
}




//check account
//support checking for undefined/null/"", will alert Error_blank
//Alapha and numberic and _ is valid, others all are inValid, will alert Error_alphanumeric
//" " on head and tail will be filter.
function chkAccount(x, fieldDesc){
	if(x == undefined || x == null || (x = trimString(x)).length == 0)return(validateUtil.setErrorMessage(validateUtil["Error_blank"].replace(/~~1/,validateUtil.getDesc(fieldDesc))+ "\n"));	
	//chkLogonChar(x,fieldDesc);
}




//check "blank"
//" " on head and tail will be filter.
function chkBlank(x, fieldDesc){
	if(x == undefined || x == null)return(validateUtil.setErrorMessage(validateUtil["Error_blank"].replace(/~~1/,validateUtil.getDesc(fieldDesc))+ "\n"));
	x = trimString(x);
	if (x.length == 0 ) {
		return(validateUtil.setErrorMessage(validateUtil["Error_blank"].replace(/~~1/,validateUtil.getDesc(fieldDesc))+ "\n"));
	}
}


//check the message whether have invalid input.
function chkMessageBody(x,fieldDesc){
	for(i=0;i<x.length;i++){
		if(x.charCodeAt(i) == 123 || x.charCodeAt(i) == 124 || x.charCodeAt(i) == 125){
			validateUtil["totalErrorMessage"] += validateUtil["Error_inValid"].replace(/~~1/, validateUtil.getDesc(fieldDesc1)) + "\n";
		}else if(x.charCodeAt(i)<32 || x.charCodeAt(i)>126){
				if(x.charCodeAt(i) != 13 && x.charCodeAt(i) != 10){
					validateUtil["totalErrorMessage"] += validateUtil["Error_inValid"].replace(/~~1/, validateUtil.getDesc(fieldDesc1)) + "\n";
				}
		}
	}
	return true;
}






//check password
//support checking for undefined/null/"", will alert Error_blank
//Alapha and numberic is valid, others all are inValid, will alert Error_alphanumeric
//" " on head and tail will be filter.
function chkPassword(x,fieldDesc){
	if(x == undefined || x == null || (x = trimString(x)).length == 0)return(validateUtil.setErrorMessage(validateUtil["Error_blank"].replace(/~~1/,validateUtil.getDesc(fieldDesc))+ "\n"));
	//if(!chkAlphaNumeric(x,fieldDesc))
	//    return(false);
	return(true);
}


//check security password
//1.length more than limitNum(parameter, default 8)
//2.should be AlphaNumeric 
function chkSecPwd(x, fieldDesc){
	if(x == undefined || x == null)return(validateUtil.setErrorMessage(validateUtil["Error_blank"].replace(/~~1/,validateUtil.getDesc(fieldDesc))+ "\n"));
	
	for(y = 0; y<x.length; y++)
	{
		charCode = x.charCodeAt(y);
		if((charCode >= 48 && charCode <=57) || (charCode >= 65 && charCode <= 90) || (charCode >=97 && charCode <= 122));
			//continue;
		else
			return(validateUtil.setErrorMessage(validateUtil["Error_secPassword"].replace(/~~1/, validateUtil.getDesc(fieldDesc))));
	}
	return(true);
}

//check security password part 2
//1.should be AlphaNumeric 
function chkSecPwd(x, y, z, fieldDesc){
	var str = [x,y,z];
	for(i = 0; i<str.length; i++)
	{
		if(str[i] == undefined || str[i] == null || trimString(str[i]).length == 0)return(validateUtil.setErrorMessage(validateUtil["Error_blank"].replace(/~~1/,validateUtil.getDesc(fieldDesc))+ "\n"));
		/*charCode = str[i].charCodeAt(0);
		if((charCode >= 48 && charCode <=57) || (charCode >= 65 && charCode <= 90) || (charCode >=97 && charCode <= 122));
			//continue;
		else
			return(validateUtil.setErrorMessage(validateUtil["Error_secPassword"].replace(/~~1/, validateUtil.getDesc(fieldDesc))));*/
	}
	return(true);
}

//check OTP
//should be Numeric 
function chkOTP(x, fieldDesc)
{
	if(x == undefined || x == null || (x = trimString(x)).length == 0)return(validateUtil.setErrorMessage(validateUtil["Error_blank"].replace(/~~1/,validateUtil.getDesc(fieldDesc))+ "\n"));
	//if(chknum(x))
		return(true);
		//	else
	//	return(validateUtil.setErrorMessage(validateUtil["Error_secPassword"].replace(/~~1/, validateUtil.getDesc(fieldDesc))));
}


//check Equal
function chkEqual(x,y,fieldDescX,fieldDescY){
	if(x!=y){
		ErrorMessage = validateUtil["Error_equal"].replace(/~~1/,validateUtil.getDesc(fieldDescX));
		return(validateUtil.setErrorMessage(ErrorMessage.replace(/~~2/,validateUtil.getDesc(fieldDescY))));
	}
	return(true);
}

///check NOT Equal
function chkNotEqual(x,y,fieldDescX,fieldDescY){
	if(x==y){
		ErrorMessage = validateUtil["Error_notEqual"].replace(/~~1/,validateUtil.getDesc(fieldDescX));
		return(validateUtil.setErrorMessage(ErrorMessage.replace(/~~2/,validateUtil.getDesc(fieldDescY))));
	}
	return(true);
}


//checkTextAreaLength'
//less than 3000 chars(parameter, col*row,no default);
function chkTextAreaLengthFocus(x, col, row, charLength, removeEnter, fieldDesc)
{	
	if(charLength == '' || charLength == undefined) charLength = 3;
	var counter = 0;	
	var theErrMsg = Error_textArea;
	
	var totalchar13 = 0;
	var totalchar10 = 0;
	var tempstr="";

	var totalLen = 0;

	for(counter=0; counter<x.length; counter++)
	{
		if(x.charCodeAt(counter)== 13) totalchar13++;
		if(x.charCodeAt(counter)== 10) totalchar10++;
	}
	if( (totalchar10>totalchar13) && (totalchar13==0) )
	{
		for(counter=0; counter<x.length;counter++)
		{
			if (x.charCodeAt(counter)==10)
				tempstr = tempstr + String.fromCharCode(13,10);
			else 
				tempstr = tempstr + x.charAt(counter);
		}
		x = tempstr;
	}

	if(removeEnter)
	{
		tempstr = "";
		for(counter=0; counter<x.length;counter++)
		{
			if ( (x.charCodeAt(counter) != 10) && (x.charCodeAt(counter) != 13) )		
				tempstr = tempstr + x.charAt(counter);
		}
		x = tempstr;
	}
	for(counter=0; counter<x.length; counter++)			
	{
		if (x.charCodeAt(counter) > 127)
			totalLen = totalLen + charLength;
		else
			totalLen = totalLen + 1;
	}
	if (totalLen > ( col * row ) )
	{
		theErrMsg = theErrMsg.replace(/~~1/, fieldDesc);
		theErrMsg = theErrMsg.replace(/~~2/, Math.floor(col * row /charLength));
		theErrMsg = theErrMsg.replace(/~~3/, col * row );
		return(validateUtil.setErrorMessageFocus(theErrMsg));
	}
	return true;
}



//check AlphaNumeric
function chkAlphaNumeric(x, fieldDesc)
{
	if(x == undefined || x == null || (x = trimString(x)).length == 0)return(validateUtil.setErrorMessage(validateUtil["Error_blank"].replace(/~~1/,validateUtil.getDesc(fieldDesc))+ "\n"));
	for(y = 0; y<x.length; y++)
	{
		charCode = x.charCodeAt(y);
		if((charCode >= 48 && charCode <=57) || (charCode >= 65 && charCode <= 90) || (charCode >=97 && charCode <= 122));
			//continue;
		else
			return(validateUtil.setErrorMessage(validateUtil["Error_alphanumeric"].replace(/~~1/, validateUtil.getDesc(fieldDesc))));
	}
	return(true);
}




function chkLogonChar(x,fieldDesc)
{
	for(y = 0; y<x.length; y++)
	{
		charCode = x.charCodeAt(y);
		if((charCode >= 48 && charCode <=57) || (charCode >= 65 && charCode <= 90) || (charCode >=97 && charCode <= 122) || (charCode ==95))
			continue;
		else
			return(validateUtil.setErrorMessage(validateUtil["Error_alphanumeric"].replace(/~~1/, validateUtil.getDesc(fieldDesc))));
	}
	return(true);
}

//check Logon ID
//contain AlphaNumeric and _
function chkLogonID(x, fieldDesc){
	x = trimString(x);
	for(i=0;i<x.length;i++)
		if(x.charCodeAt(i)==32) {
			return(validateUtil.setErrorMessage(validateUtil["Error_inValid"].replace(/~~1/, validateUtil.getDesc(fieldDesc))));
		}
	if(!chkLogonChar(x)) {
		return(validateUtil.setErrorMessage(validateUtil["Error_inValid"].replace(/~~1/, validateUtil.getDesc(fieldDesc))));
	}
	return true;
}

//chkMinLength
//length should not less than y(parameter, no default);
function chkMinLength(x,y,fieldDesc){
	if(x.length<y){
		ErrorMessage=validateUtil["Error_limitNum"].replace(/~~1/,validateUtil.getDesc(fieldDesc));
		return(validateUtil.setErrorMessage(ErrorMessage.replace(/~~2/,y)));}
	else
		return true;
}

//check MaxLength
//length should not more than y(parameter, no default);
function chkMaxLength(x,y,fieldDesc){
	if(x.length>y){
		ErrorMessage=validateUtil["Error_mostNum"].replace(/~~1/,validateUtil.getDesc(fieldDesc));
		return(validateUtil.setErrorMessage(ErrorMessage.replace(/~~2/,y)));}
	else
		return true;
}

//check EqualLength
//length should equal y(parameter, no default);
function chkEqualLength(x, y, fieldDesc){
	if(x.length != y){
		ErrorMessage=validateUtil["Error_equal"].replace(/~~1/,validateUtil.getDesc(fieldDesc));
		return(validateUtil.setErrorMessage(ErrorMessage.replace(/~~2/,y)));}
	else
		return true;
}


//check Alphabetic
function chkAlphabetic(x, fieldDesc)
{
	for(y = 0; y<x.length; y++)
	{
		charCode = x.charCodeAt(y);
		if((charCode >= 65 && charCode <= 90) || (charCode >=97 && charCode <=122))
			continue;
		else
			return(validateUtil.setErrorMessage(validateUtil["Error_alphabetic"].replace(/~~1/, validateUtil.getDesc(fieldDesc))));
		return(true);
	}
	return(true);
}

//check Not Smaller
//x should Not small than y(parameter, no default)
function chkNotSmallerThan(x,y,fieldDesc)
{
	tempx = trimSeparator(x);
	tempy = trimSeparator(y);

	if(parseFloat(tempx) < parseFloat(tempy)){
		ErrorMessage = validateUtil["Error_small"].replace(/~~1/, validateUtil.getDesc(fieldDesc));
		return(validateUtil.setErrorMessage(ErrorMessage.replace(/~~2/, y)));
	}
	else
		return(true);
}

///check Not Greater
//x should Not greater than y(parameter, no default)
function chkNotGreaterThan(x,y,fieldDesc)
{
	tempx = trimSeparator(x);
	tempy = trimSeparator(y);

	if(parseFloat(tempx) > parseFloat(tempy)){
		ErrorMessage = validateUtil["Error_great"].replace(/~~1/, validateUtil.getDesc(fieldDesc));
		return(validateUtil.setErrorMessage(ErrorMessage.replace(/~~2/, y)));
	}
	else
		return(true);
}



//Compare date
//x should later than y
//format for x and y should be "DD/MM/YYYY"  "8/02/2012" or "8 Feb 2012"
function chkDateComparsion(x, y, fieldDesc, fieldDesc2)
{
	if(Date.parse(convertEngDate(x)) >= Date.parse(convertEngDate(y)))
		return(true);
	else
	{
		ErrorMessage = validateUtil["Error_early"].replace(/~~1/, validateUtil.getDesc(fieldDesc));
		return(validateUtil.setErrorMessage(ErrorMessage.replace(/~~2/, validateUtil.getDesc(fieldDesc2))));
	}
}

//Date util
function convertEngDate(x)
{
        var tmpx=convertDateFormat(x);
        if ( tmpx == "" )
        {
                return x;
        }

        var s1pos, s2pos;
        s1pos = tmpx.indexOf( "/" );
        if ( s1pos > 0 )
        {
                s2pos = tmpx.indexOf( "/", s1pos + 1 );
                if ( s2pos < 0 )
                {
                        return x;
                }
        }
        else
        {
                return x;
        }
        DD = tmpx.substring(0,s1pos);
	if ( DD.length == 1 ) {
		DD = "0" + DD;
	}
        MMM = tmpx.substring(s1pos+1,s2pos);
        YYYY = tmpx.substring(s2pos+1,tmpx.length);
        // processing date
        if(MMM=="1" || MMM=="01")MMM="JAN";
        else if(MMM=="2" || MMM=="02")MMM="FEB";
        else if(MMM=="3" || MMM=="03")MMM="MAR";
        else if(MMM=="4" || MMM=="04")MMM="APR";
        else if(MMM=="5" || MMM=="05")MMM="MAY";
        else if(MMM=="6" || MMM=="06")MMM="JUN";
        else if(MMM=="7" || MMM=="07")MMM="JUL";
        else if(MMM=="8" || MMM=="08")MMM="AUG";
        else if(MMM=="9" || MMM=="09")MMM="SEP";
        else if(MMM=="10")MMM="OCT";
        else if(MMM=="11")MMM="NOV";
        else if(MMM=="12")MMM="DEC";
        else MMM="XXX";
        return DD+" "+MMM+" "+YYYY;

}

function convertDateFormat(x){
        var tmpx=x;
        var s1pos, s2pos;

        if ( !(tmpx.indexOf( " " ) < 0 ))
        {
                var sp1, sp2;
                sp1 = tmpx.indexOf( " " );
                DD=tmpx.substring( 0, sp1 );
                sp2 = tmpx.indexOf( " ", sp1 + 1 );
                if ( sp2 < 0 )
                {
                        return "";
                }
                MM = ( tmpx.substring( sp1 + 1, sp2 ).toUpperCase());
                YYYY = tmpx.substring( sp2 + 1, tmpx.length );
                if(MM=="JAN")MM="01";
                else if(MM=="FEB")MM="02";
                else if(MM=="MAR")MM="03";
                else if(MM=="APR")MM="04";
                else if(MM=="MAY")MM="05";
                else if(MM=="JUN")MM="06";
                else if(MM=="JUL")MM="07";
                else if(MM=="AUG")MM="08";
                else if(MM=="SEP")MM="09";
                else if(MM=="OCT")MM="10";
                else if(MM=="NOV")MM="11";
                else if(MM=="DEC")MM="12";
                else return "";
                tmpx = DD + "/" + MM + "/" + YYYY;
        }
        s1pos = tmpx.indexOf( "/" );
        if ( s1pos < 0 )
        {
                if ( tmpx.length == 8 )
                {
                        s1pos = 2;
                        s2pos = 5;
                        tmpx = tmpx.substring( 0, 2 ) + "/" + tmpx.substring( 2, 4 ) + "/" + tmpx.substring( 4, 8 );
                }
                else
                {
                        return "";
                }
        }
        else
        {
               s2pos = tmpx.indexOf( "/", s1pos + 1 );
               if ( s2pos < 0 )
               {
                        return "";
               }
        }
        if ( !chknum( tmpx.substring(0, s1pos )) || !chknum( tmpx.substring( s1pos + 1, s2pos )) || !chknum( tmpx.substring( s2pos + 1, tmpx.length )) || tmpx.substring( s2pos + 1, tmpx.length ) < 1900)
        {
                return "";
        }
        return tmpx;
}

//check NotEarlyThanToday
//x should later than today
//format for x should be "YYYY/MM/DD" "2012/4/3" or "03 APR 2012"
function chkNotEarlyThanToday(x, fieldDesc)
{
	var Today = new Date();
	var Now = Today.getFullYear() + "/" + (Today.getMonth()+1) + "/" +Today.getDate();
	if(Date.parse(x) >= Date.parse(Now))
		return(true);
	else
		return(validateUtil.setErrorMessage(validateUtil["Error_earlyToday"].replace(/~~1/, validateUtil.getDesc(fieldDesc))));
}

//check LeapYear
function isLeapYear(x)
{
	if(x/400 == parseInt(x/400))
		return(true);
	else if(x/100 == parseInt(x/100))
		return(false);
	else if(x/4 == parseInt(x/4))
		return(true);
	else
		return(false);
}

//check Numeric(0-9)
function chkNumeric(x, fieldDesc)
{
	if(x == undefined || x == null || (x = trimString(x)).length == 0)return(validateUtil.setErrorMessage(validateUtil["Error_blank"].replace(/~~1/,validateUtil.getDesc(fieldDesc))+ "\n"));
	if(chknum(x))
		return(true);
	else
		return(validateUtil.setErrorMessage(validateUtil["Error_numeric"].replace(/~~1/, validateUtil.getDesc(fieldDesc))));

}


//check Amount
//all number
//can check the format with "," and ".", eg:"11,111,111.01"
function chkAmount(x, fieldDesc){

	return(chkPositive(x,fieldDesc));
}
function chkAmountNG(x, fieldDesc){

	return(chkNonNegative(x, fieldDesc));
}
function trimSeparator(x){

	Start_Point = 0;
	End_Point = x.indexOf(",", Start_Point);
	while(End_Point != -1){
		x = x.substring(0, End_Point) + x.substring(End_Point+1, x.length);
		if(x.indexOf(",") == End_Point){
			End_Point = x.indexOf(",", End_Point);
			}else 
				End_Point = x.indexOf(",", End_Point + 1);
	}
	return(x);
}

function chkAmountSeparator(x, fieldDesc){
	noSeparator=trimSeparator(x);
	if(chkFloat(noSeparator,fieldDesc)){
		if(chkSeparator(x,fieldDesc))
			return true;
		return(validateUtil.setErrorMessage(validateUtil["Error_inValidSeparator"].replace(/~~1/, validateUtil.getDesc(fieldDesc))));
	}
	else
		return false;
}
function chkSeparator(x,fieldDesc){
	if(x.charAt(0) == "-")
		x = x.substring(1, x.length);

	FirstSeparator = x.indexOf(",", 0);
	if(FirstSeparator <=3 && FirstSeparator > 0)
	{
		Start_Point = FirstSeparator + 1;
		Found = true;

		while(Found)
		{
			End_Point = x.indexOf(",", Start_Point);
			Offset = End_Point - Start_Point;
			if(End_Point == -1)
			{
				Tail = x.substring(Start_Point, x.length).length;

				if(x.substring(Start_Point+3, Start_Point+4) == ".")
				{
					Start_Point += 4;
					if(x.indexOf(",", Start_Point) == -1 && x.indexOf(".", Start_Point)== -1)
						return true;
					else
						return false;

				}
				else if(Tail != 3 || (Tail==3 && x.charAt(x.length-1)==".")){
					return false;
				}
				else if(Tail == 3)
					return(true);

			}
			else if(Offset != 3){
				return false;
			}
			Start_Point = End_Point + 1;
		}
	}
	else if(x.indexOf(",",0) != -1 && FirstSeparator > 3)
		return false;
	else if(x.indexOf(".", 0) == -1 && x.indexOf(",",0) == -1)
		return(true);
	else if(x.indexOf(".", 0) != -1)
	{
		return true;
	}
	else
		return false;
}


function chknum(x){

	for(y=0; y<x.length; y++)
	{
 		if(x.charCodeAt(y) > 57 || x.charCodeAt(y) < 48)
			return(false);
	}
	return(true);
}

//check valid input
//valid character : "0~9", "a~z", "A~Z", "\r", "\n", ":", "?", ".", ",", "(", ")", " ", "'" 
function chkValidCharacters(x, fieldDesc){

	for(y=0 ; y < x.length ; y++)
	{
		charCode = x.charCodeAt(y);

		if((charCode >= 48 && charCode <=57) || (charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122) || charCode == 10 || charCode == 13 || charCode == 58 || charCode==63 || charCode==46 || charCode==44 || charCode==40 || charCode==41 || charCode==32 || charCode==39)
			continue;
		else
			return(validateUtil.setErrorMessage(validateUtil["Error_inValid"].replace(/~~1/, validateUtil.getDesc(fieldDesc))));
	}
	return(true);
}

//check whether its a float
//first char can be one and only one "-", "."
//non-first should be number(0~9)
function chkFloat(x,fieldDesc){
	ErrorMessage = validateUtil["Error_inValidNumber"].replace(/~~1/, validateUtil.getDesc(fieldDesc));
	if(chkFloatingPoint(x))
		return true;
	return(validateUtil.setErrorMessage(ErrorMessage));
}

function chkFloatingPoint(x) {

	var string_len = x.length;
	var decimal_counter = 0;
	var temp_string;
	var start = 0;

	if(x.substring(0,1) == "-")
		start = 1;
	else if(x.substring(0,1) == "."){
		start = 1;
		decimal_counter++;
	}

	if(x.substring(start,x.length).length ==0)
		return(false);

	for(y=start; y<string_len; y++)
	{
		temp_string = x.substring(y,y+1);
		if(isNaN(parseInt(temp_string)))
		{
			if(temp_string == "." && decimal_counter == 0)
				decimal_counter++;
			else
				return(false);
		}
	}
	return (true);
}

function chkNonNegative(x, fieldDesc){

	if(chkAmountSeparator(x,fieldDesc))
		x = trimSeparator(x);
	else
		return(false);

	if(chkFloat(x,fieldDesc)){

		if(parseFloat(x) >= 0)
			return(true);
		else
			return(validateUtil.setErrorMessage(validateUtil["Error_positive"].replace(/~~1/, validateUtil.getDesc(fieldDesc))));
	}
	else{
		return(false);
	}
}

function chkPositive(x, fieldDesc){

	if(chkAmountSeparator(x,fieldDesc))
		x = trimSeparator(x);
	else
		return(false);

	if(chkFloat(x,fieldDesc)){

		if(parseFloat(x) > 0)
			return(true);
		else
			return(validateUtil.setErrorMessage(validateUtil["Error_positive"].replace(/~~1/, validateUtil.getDesc(fieldDesc))));
	}
	else{
		return(false);
	}
}



//check emailAddress
function chkEmailAddr(x, fieldDesc)
{
		chkBlank(x, fieldDesc);
	
		for(y=0; y<x.length; y++)
		{
			charCode = x.charCodeAt(y);

			if((charCode >= 48 && charCode <=57) || (charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122) || (charCode >= 35 && charCode <= 39) || charCode == 43 || (charCode >= 45 && charCode <= 47) || charCode==63 || charCode==64 || charCode==95)
				continue;
			else
				return(validateUtil.setErrorMessage(validateUtil["Error_inValid"].replace(/~~1/, validateUtil.getDesc(fieldDesc))));
		}

		var s1 = x.indexOf("@");
		var s2 = x.lastIndexOf("@");
		if (s1 != s2 || s1 <= 0 || s1 >= x.length-1) {
			return(validateUtil.setErrorMessage(validateUtil["Error_inValid"].replace(/~~1/,validateUtil.getDesc(fieldDesc))));
		}

		s1 = x.indexOf(".");
		s2 = x.lastIndexOf(".");
		if (s1 == 0 || s2 == x.length-1) {
			return(validateUtil.setErrorMessage(validateUtil["Error_inValid"].replace(/~~1/,validateUtil.getDesc(fieldDesc))));
		}

		if (x.indexOf("..") != -1) {
			return(validateUtil.setErrorMessage(validateUtil["Error_inValid"].replace(/~~1/,validateUtil.getDesc(fieldDesc))));
		}

		s1 = x.indexOf(".@");
		s2 = x.indexOf("@.");
		if (s1 != -1 || s2 != -1) {
			return(validateUtil.setErrorMessage(validateUtil["Error_inValid"].replace(/~~1/,validateUtil.getDesc(fieldDesc))));
		}
		return(true);

}



//check phone number
function chkPhone(x, fieldDesc)
{
	if(chkPhoneNumbers(x))
		return(true);
	else
		return(validateUtil.setErrorMessage(validateUtil["Error_phone"].replace(/~~1/, validateUtil.getDesc(fieldDesc))));

}


function chkPhoneNumbers(x, fieldDesc){

	for(y=0; y<x.length; y++)
	{
 		if((x.charCodeAt(y) > 57 || x.charCodeAt(y) < 48) && x.charCodeAt(y) != 32)
			return(validateUtil.setErrorMessage(validateUtil["Error_phone"].replace(/~~1/, validateUtil.getDesc(fieldDesc))));
	}
	return(true);

}



function trimString(x)
{
	while (x.substring(0,1) == " " ||x.substring(0,1).charCodeAt() == 160)
	{	templength=x.length;
		x = x.substring(1,templength);
	}

	while (x.substring(x.length-1,x.length) == " " ||x.substring(0,1).charCodeAt() == 160)
	{	x=x.substring(0,x.length-1)
	}
	return x
}

function trimTextAreaString(x)
{
	var tempStr = "";
	var c = '';
	for(var i=0; i<x.length; ++i) {
		c = x.charCodeAt(i);
		if((c != 32) && (c != 13) && (c != 10)) {
			tempStr += x.substring(i, i+1);
		}
	}
	return tempStr;
}








